import {useState} from "react";
import {DictDataVO} from "@/services/DictDataService";
import {ProSchemaValueEnumMap, ProSchemaValueEnumObj} from "@ant-design/pro-utils/es/typing";

export default () => {
  const [dict, setDict] = useState<Map<string, DictDataVO[]>>(new Map())
  // @ts-ignore
  const getDictList: (idx: string) => DictDataVO[] | undefined = (idx: string) => dict && dict[idx]
  const getDictData: (idx: string, value: string) => DictDataVO | undefined = (idx: string, value: string) => {
    return getDictList(idx)?.find(c => c.value === value)
  }
  const getDictEnum: (idx: string) => ProSchemaValueEnumMap = (idx) => {
    let dictList = getDictList(idx);
    return dictList?.reduce((acc, curr) => {
      // @ts-ignore
      acc[curr.value] = {text: curr.label, status: curr.colorType}
      return acc
    }, {}) as ProSchemaValueEnumMap
  }

  return {dict, setDict, getDictData, getDictList, getDictEnum}
}
